<?php

class Type
{
	private $id; // string
	private $description; // string
	
	private $datafields; // array(Datafield.id => Datafield)
	
	private $parents; // array(Type.id => Type)
	private $children; // array(Type.id => Type)
	
	public function __construct($args)
	{
		// Id
		if (!isset($args['id']))
		{
			die('Error 3');
		}
		$this->id = strtolower($args['id']);
		
		// Description
		if (!isset($args['description']))
		{
			$args['description'] = '';
		}
		$this->description = $args['description'];
		
		// Datafields
		if (!isset($args['datafields']))
		{
			$args['datafields'] = array();
		}
		$this->datafields = $args['datafields'];
		
		// Parents
		if (!isset($args['parents']))
		{
			$args['parents'] = array();
		}
		$this->parents = $args['parents'];
		
		// Children
		$this->children = array();
	}
	
	public function getElders()
	{
		$elders = array();
		
		foreach ($this->parents as $parent)
		{
			$elders []= (string)$parent;
			$elders = array_merge($elders, $parent->getElders($elders));
		}
		
		return $elders;
	}
	
	public function getSiblings()
	{
		$siblings = array();
		
		foreach ($this->children as $child)
		{
			$siblings []= (string)$child;
			$siblings = array_merge($siblings, $child->getElders($siblings));
		}
		
		return $siblings;
	}
	
	public function __toString()
	{
		return $this->id;
	}
}

?>